﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using tmAsk.Common;

namespace tmAsk.Webs
{
    public partial class install_ : System.Web.UI.Page
    {

        tmAsk.Data.MakehtmlSQL SQL = new tmAsk.Data.MakehtmlSQL();
        function make_htm = new function();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnNext_Click(object sender, EventArgs e)
        {
            if (function.CheckNull(txtAdminUserName.Text, txtAdminUserPass.Text))
            {
                DataTable dt = SQL.GetList("select * from B_admin where a_username='" + txtAdminUserName.Text + "'").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    SQL.ExecuteSql("update B_admin set a_userpassword='" + make_htm.Md5(txtAdminUserPass.Text) + "' where a_username='" + txtAdminUserName.Text + "'");
                }
                else
                {
                    SQL.Add("insert into B_admin(a_username,a_userpassword) values('" + txtAdminUserName.Text + "','" + make_htm.Md5(txtAdminUserPass.Text) + "')");
                }
            }
            if (function.CheckNull(txtTitle.Text, txtUrl.Text, txtUserName.Text, txtUserPoint.Text, txtSetTime.Text))
            {
                string isCheck = Temp(rdoIsCheck);
                string isVisitors = Temp(rdoIsVisitors);

                DataTable dt = SQL.GetList("select c_id from B_config").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    SQL.ExecuteSql("update B_config set c_title='" + txtTitle.Text + "',c_url='" + txtUrl.Text + "',c_isCheck=" + isCheck + ",c_setTime=" + txtSetTime.Text + ",c_count='" + txtCount.Text + "',c_defaultname='" + txtUserName.Text + "',c_defaultpoint=" + txtUserPoint.Text + ",c_index = '/?default'");
                }
                else
                {
                    SQL.Add("insert into B_config(c_title,c_url,c_isCheck,c_setTime,c_count,c_defaultname,c_defaultpoint,c_index) values('" + txtTitle.Text + "','" + txtUrl.Text + "'," + isCheck + "," + txtSetTime.Text + ",'" + txtCount.Text + "','" + txtUserName.Text + "'," + txtUserPoint.Text + ",'/?default')");
                }
                //

                (new function()).DeleteFile("install.aspx");
                (new function()).DeleteFile("install.aspx.cs");
                (new function()).DeleteFile("install_.aspx");
                (new function()).DeleteFile("install_.aspx.cs");

                Response.Write(function.alert_text(2, "安装完成，为了安全起见，已删除安装文件", "/?default"));
            }
        }
        public static string Temp(RadioButton rdoButton)
        {
            if (rdoButton.Checked)
            {
                return "1";
            }
            return "0";
        }
    }
}